package com.example.myapplication.Callback;

import com.example.myapplication.Bean.BaseResponse;
import com.google.gson.Gson;

import mylibrary.callback.BaseCallBack;

public abstract class HttpCallBack<T>extends BaseCallBack<T> {
    BaseResponse baseResponse;

    @Override
    protected T onConver(String result) {
        T t=null;
        baseResponse = new Gson().fromJson(result, BaseResponse.class);
        if (baseResponse!=null&&isSucessFull()){
            t=convert(baseResponse.getData());

        }else {
            error(baseResponse.getErrorMsg(),baseResponse.getErrorCode());
        }
        return t;
    }

    @Override
    public boolean isSucessFull() {
        return baseResponse.getErrorCode()==0;
    }
}
